package com.znzz.controller;

import com.znzz.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/helloSpringBoot")
public class HelloController {

    private Environment env;//封装全部对象到Environment的对象

    @Autowired
    public void setEnv(Environment env) {
        this.env = env;
    }

    @Autowired
    private MyDataSource dataSource;

    /*读取配置文件信息*/
    @Value("${name}")
    private String name;
    @Value("${sex}")
    private String sex;
    @Value("${user.name}")
    private String name0;
    @Value("${likes[1]}")
    private String game;
    @Value("${subject.java.b}")
    private String subject;
    @Value("${users[1].name}")
    private String user;
    @Value("${tempq}")
    private String temp;
    @Value("${lesson}")
    private String lesson;


    @GetMapping
    public String hello() {
        System.out.println("hello springboot.....^_^");
        System.out.println("====>>" + name);
        System.out.println("====>>" + sex);
        System.out.println("====>>" + name0);
        System.out.println("====>>" + game);
        System.out.println("====>>" + user);
        System.out.println("====>>" + subject);
        System.out.println("====>>" + temp);
        System.out.println("====>>" + lesson);
        System.out.println("==================================");
        System.out.println(env.getProperty("tempq"));
        System.out.println(env.getProperty("likes[1]"));
        System.out.println("======================");
        System.out.println(dataSource);
        return "<h1>hello springboot.....^_^<h1>";
    }
}
